﻿using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.Menu;
using B.S.BasicData.Read.DTOS;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.Menu
{
    public class GetmenunameHandler : IRequestHandler<GetmenunameCommon, ApiResult<List<MenuNameDTO>>>
    {
        private readonly IBaseRepository<menuModel> menuRepo;

        public GetmenunameHandler(IBaseRepository<menuModel> menuRepo)
        {
            this.menuRepo = menuRepo;
        }

        public Task<ApiResult<List<MenuNameDTO>>> Handle(GetmenunameCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<MenuNameDTO>> res = new ApiResult<List<MenuNameDTO>>();

            var info = menuRepo.GetAll().Where(x => x.IsDeleted == false).Select(x=> new MenuNameDTO()
            {
                MenuId = x.MenuId,
                MenuName = x.MenuName,
            }).ToList();

            res.Code = ApiEnum.Success;
            res.Data = info;
            res.Message = "菜单下拉框查询成功";
            return Task.FromResult(res);
        }
    }
}
